# -*- coding: utf-8 -*-
from sqlalchemy import Column, String, Integer

from apps.db import BaseModel


class Application(BaseModel):
    __tablename__ = 'tb_application'
    name = Column(String)
    effective_date = Column(String)
    description = Column(String)
    state = Column(Integer)
    image = Column(String)
    version = Column(String)

    def __init__(self, *args, **kwargs):
        super(Application, self).__init__()
        for attr, value in kwargs.items():
            if attr in self.__column_name_list__() and getattr(self, attr) is None:
                setattr(self, attr, value)

    @classmethod
    def init_record(cls):
        data = Application.get('1')
        if data is None:
            app = Application(**{
                'id': '1',
                'name': u'房管局填报流程',
                'effective_date': '2099-01-01',
                'description': u'房管局填报流程',
                'state': 1,
                'image': 'http://21.154.3.226:5000/assets/get?id=logo.png',
                'version': '1.0.0'
            })
            app.id = '1'
            app.save(commit=True)
